package com.artezio.buyndrive.dao.impl;

import com.artezio.buyndrive.dao.TurnDAO;
import com.artezio.buyndrive.domain.Carservice;
import com.artezio.buyndrive.domain.SectionTurn;
import com.artezio.buyndrive.domain.Turn;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TurnDAOImpl extends AbstractHibernateDao<Turn>
        implements TurnDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public TurnDAOImpl() {
        super.setSessionFactory(sessionFactory);
    }

    @Override
    public List<Turn> getByCarserviceAndSection(Carservice carservice, SectionTurn sectionTurn) {
            Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Turn.class);
            if(carservice != null){
                criteria.add(Restrictions.eq("idCarservice", carservice));
            }
            if(sectionTurn != null){
                criteria.add(Restrictions.eq("idSectionTurn", sectionTurn));
            }
            return criteria.list();
    }
}